package com.dkd.day20250615;

import com.dkd.day20250614.ListNode;

public class SolutionFindFirstCommonNode {
    public static void main(String[] args) {

    }
    public static  ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        //伪码
        //分别压入set，第一个contanins就是第一个公告节点
        return null;
    }

    public static  ListNode FindFirstCommonNode2(ListNode pHead1, ListNode pHead2) {
       //双指针，L1和L2同时走，走完换路，速度相同，迟早相遇
        ListNode l1 = pHead1, l2 = pHead2;
        while(l1 != l2){
            l1 = (l1==null)?pHead2:l1.next;
            l2 = (l2==null)?pHead1:l2.next;
        }
        return l1;
    }
}
